/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import docs.ApplicationModel;
import docs.InternshipCompanyModel;
import org.netbeans.xml.schema.elements.APPLICATIONTYPE;
import org.netbeans.xml.schema.elements.COMPANYTYPE;
import org.netbeans.xml.schema.elements.LISTIDTYPE;
import org.netbeans.xml.schema.elements.NOTIFSTYPE;
import org.netbeans.xml.schema.elements.PERSONNELTYPE;
import org.netbeans.xml.schema.elements.STUDENTTYPE;
import org.netbeans.xml.schema.elements.USERTYPE;

/**
 *  Class for web service communication
 * @author metbill
 */
public class BusControl {
    
    /* Services offerts par notre database */
      static int authenticate(java.lang.String username, java.lang.String password) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.authenticate(username, password);
    }

    static NOTIFSTYPE getNotifications(int idTo) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getNotifications(idTo);
    }

   static USERTYPE getinfoUserbyId(int requestId) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getinfoUserbyId(requestId);
    }

    static STUDENTTYPE getStudentbyId(int idUser) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getStudentbyId(idUser);
    }

    static COMPANYTYPE getCompanybyId(int idUser) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getCompanybyId(idUser);
    }

    static LISTIDTYPE getCompanies() {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getCompanies();
    }

    static PERSONNELTYPE getPersonnelbyId(int idUser) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getPersonnelbyId(idUser);
    }
    

       
    static void createApplication(int idStud, int idCpany, int idApplication, int state) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        port.createApplication(idStud, idCpany, idApplication, state);
    }

    static APPLICATIONTYPE getApplications(int idStud) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getApplications(idStud);
    }
    
    static int creerNotification(int idTo, int idFrom, java.lang.String message) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.creerNotification(idTo, idFrom, message);
    }
    
    
        /* Services offerts par la companie*/
    
    static java.util.List<docs.InternshipCompanyModel> getOffers(docs.InternshipInputModel internships) {
        docs.GetCompanyOffersService service = new docs.GetCompanyOffersService();
        docs.GetCompanyOffers port = service.getGetCompanyOffersPort();
        return port.getOffers(internships);
    }

    static java.util.List<docs.ApplicationModel> getAppListForCompany(int internshipsId) {
        docs.GetApplicationListService service = new docs.GetApplicationListService();
        docs.GetApplicationList port = service.getGetApplicationListPort();
        return port.getAppListForCompany(internshipsId);
    }
    
    static int addNewApplicant(docs.ApplicationModel newAapplicant) {
        docs.AddNewApplicationService service = new docs.AddNewApplicationService();
        docs.AddNewApplication port = service.getAddNewApplicationPort();
        return port.addNewApplicant(newAapplicant);
    }
    

    static InternshipCompanyModel getOffersById(int internshipsID) {
        docs.GetCompanyOffersService service = new docs.GetCompanyOffersService();
        docs.GetCompanyOffers port = service.getGetCompanyOffersPort();
        return port.getOffersById(internshipsID);
    }   

    static LISTIDTYPE getStudentsSupervisor(int idSupervisor) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.getStudentsSupervisor(idSupervisor);
    }


   static docs.ApplicationModel getAppById(int internshipsId) {
        docs.GetApplicationListService service = new docs.GetApplicationListService();
        docs.GetApplicationList port = service.getGetApplicationListPort();
        return port.getAppById(internshipsId);
    }

    static boolean updateApplicationStatus(int response, int applicationID) {
        docs.UpdateApplicationService service = new docs.UpdateApplicationService();
        docs.UpdateApplication port = service.getUpdateApplicationPort();
        return port.updateApplicationStatus(response, applicationID);
    }
    
        
    static String uploadCV(byte[] cv) {
        insa.ws.convetion.ConventionWSService service = new insa.ws.convetion.ConventionWSService();
        insa.ws.convetion.ConventionWS port = service.getConventionWSPort();
        return port.uploadCV(cv);
    }

        
    static String generateConvention(java.lang.String studentFirstName, java.lang.String studentLastName, int studentID, java.lang.String companyName, int companyID, java.lang.String companyMail, java.lang.String companyAddress, java.lang.String companySIRET, java.lang.String c, java.lang.String detailsOffer) {
        insa.ws.convetion.ConventionWSService service = new insa.ws.convetion.ConventionWSService();
        insa.ws.convetion.ConventionWS port = service.getConventionWSPort();
        return port.generateConvention(studentFirstName, studentLastName, studentID, companyName, companyID, companyMail, companyAddress, companySIRET, c, detailsOffer);
    }

    static int genAccount(java.lang.String username, org.netbeans.xml.schema.elements.COMPANYTYPE company) {
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService service = new org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLService();
        org.netbeans.j2ee.wsdl.wismiservice.userwsdl.UserWSDLPortType port = service.getUserWSDLPort();
        return port.genAccount(username, company);
    }
    
    
}
